"""
Author        yongfa
Date          2022-07-21 09:47:30
LastEditTime  2023-09-07 08:11:10
LastEditors   yongfa
Description   celery配置文件
"""

import multiprocessing
import os


class CeleryConfig:

    # redis
    REDIS_HOST = os.getenv('REDIS_HOST', '172.19.43.180')
    REDIS_PORT = os.getenv('REDIS_PORT', 6379)
    REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', '123456')
    REDIS_DB = os.getenv('REDIS_DB', 10)

    # celery  | redis
    broker_url = 'redis://:{password}@{host}:{port}/{db}'.format(
        password=REDIS_PASSWORD,
        host=REDIS_HOST,
        port=REDIS_PORT,
        db='9')
    result_backend = 'redis://:{password}@{host}:{port}/{db}'.format(
        password=REDIS_PASSWORD,
        host=REDIS_HOST,
        port=REDIS_PORT,
        db='10')

    worker_hijack_root_logger = False  # 关掉
    task_serializer = 'msgpack'
    result_serializer = 'json'
    result_expires = 60 * 60 * 24
    accept_content = ['json', 'msgpack']
    # 定时任务
    timezone = 'Asia/Shanghai'
    enable_utc = False

    # 日志 TODO 目前没生效
    # celeryd_log_level = 'ERROR'

    # 并发数
    worker_concurrency = 2
    if os.getenv('APP_SETTINGS') == 'prod':
        worker_concurrency = multiprocessing.cpu_count()
